package dao;

import entity.Usuario;
import java.io.Serializable;
import javax.transaction.Transaction;
import org.hibernate.Session;
import util.HibernateUtil;
 
/**
 *
 * @author CesarFrantz
 */
public class UsuarioDAO implements Serializable {

   
    private Session sessao;
    private Transaction trans;
 
    public UsuarioDAO() {}
    
    public void addUsuario(Usuario u){
        try {
            sessao = HibernateUtil.getSessionFactory().openSession();
            trans = (Transaction) sessao.beginTransaction();
            Usuario user = new Usuario();
            user.setCompleteName(u.getCompleteName());
            user.setEmail(u.getEmail());
            user.setEndereco(u.getEndereco());
            user.setIdade(u.getIdade());
            user.setSenha(u.getSenha());
            user.setTelefone(u.getTelefone());
            user.setUsuario(u.getUsuario());
            sessao.persist(user);
            trans.commit();
            
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            sessao.close();
        }        
    }

    public void removeUsuaro (Usuario u){
         try {
            sessao = HibernateUtil.getSessionFactory().openSession();
            trans = (Transaction) sessao.beginTransaction();
            
            sessao.delete(u);
            trans.commit();
            
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            sessao.close();
        }       
    }                   
    
}
